﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using AMS.DataAccess.Interfaces;
using AMS.DataAccess.BO;

public partial class Customer_MyCustomers : BaseWorkPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DoDataBind();
        }
    }

    private int rowIndex = 0;
    protected string RowIndex
    {
        get { return (++rowIndex).ToString(); }
    }

    private void TestDataBind()
    {
        List<int> list = new List<int>();
        for (int i = 0; i < 25; i++)
        {
            list.Add(i);
        }

        gv.DataSource = list;
        gv.DataBind();
        BindPager(pager);
        BindPager(pager2);
    }

    #region Not used
    ////void DoDataBind()
    ////{
    ////    int total = 0;
    ////    DataTable dt = Pager.getTable("TC_Customer",
    ////        "[AID] ,[Name] ,[Name_En] ,[CustomerType] ,[isApplicant] ,[isCustomer] ,[CityName] ,[Fax] ,[Tel] ,[CreateDate]",
    ////        GetWhere(),
    ////        string.Empty,
    ////        string.Empty,
    ////        pager.CurrentPageIndex,
    ////        pager.PageSize,
    ////        ref total);

    ////    gv.DataSource = dt;
    ////    gv.DataBind();
    ////    lblAllCustomerCount.Text = total.ToString();
    ////    BindPager(total);

    ////    if (dt.Rows.Count == 0)
    ////    {
    ////        MsgWarning("无记录");
    ////    }

    ////    //lblAllCustomerCount.Text = 100.ToString();
    ////    //TestDataBind();
    ////}

    ////private string GetWhere()
    ////{
    ////    return string.Format("CreateUser='{0}'", Session[Globals.USER_ID]);
    ////}
    #endregion

    void DoDataBind()
    {
        int total = 0;
        ICustomerManager manager = ManagerFactory.CreateCustomerManager();
        List<CustomerInfo> list = manager.GetMyPagedCustomers(
            CallContext,
            pager.CurrentPageIndex, 
            pager.PageSize,
            out total);

        gv.DataSource = list;
        gv.DataBind();

        lblAllCustomerCount.Text = total.ToString();
        BindPager(total);

        if (list.Count == 0)
        {
            MsgWarning("无记录");
        }

    }

    private void BindPager(int total)
    {
        pager.RecordCount = total;
        pager2.RecordCount = total;
    }

    protected string GetCustomerClass(bool isApplicant, bool isCustomer)
    {
        return string.Empty;
    }

    protected string GetCustomerType(int typeCode)
    {
        return string.Empty;
    }

    private void BindPager(Wuqi.Webdiyer.AspNetPager pg)
    {
        pg.RecordCount = 8000;
        pg.PageSize = 20;
    }

    protected void pager_PageChanged(object sender, EventArgs e)
    {
        pager2.CurrentPageIndex = pager.CurrentPageIndex;
        DoDataBind();
    }

    protected void pager2_PageChanged(object sender, EventArgs e)
    {
        pager.CurrentPageIndex = pager2.CurrentPageIndex;
        DoDataBind();
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        DoDataBind();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        //
    }
}
